<template>
	<web-view
		src="/static/game/index.html"
		@message="handleMessage"
	>
	</web-view>
	<!-- οnlοad="this.height=this.contentWindow.document.documentElement.scrollHeight" -->
</template>
<script>
	export default {
		onLoad() {
			// #ifdef APP-PLUS
			plus.screen.unlockOrientation();
			plus.screen.lockOrientation('landscape-primary');
			// #endif
			// plus.screen.lockOrientation("landscape-primary");
		
		},
		onUnload() {
			plus.screen.lockOrientation('portrait-primary');
			// uni.redirectTo({
			// 	url: '../empty/empty/'
			// })
			return true
		},
		methods: {
			// 记录得分
			handleMessage(data) {
				let acc = uni.getStorageSync("accountInfo")
				let token = uni.getStorageSync("usertoken");
				// 毫秒 ==> 秒, 向下取整，非四舍五入
				const time = Math.floor((data?.detail?.data?.[0].time || 0) / 1000)
				const gamescore = data?.detail?.data?.[0].point
				const parms = {
					phonenum: acc.phone, // 手机号
					time, // 时长
					gamescore, // 分数
				}
				uni.request({
					url: this.serverUrl + "/train/inputGameScore",
					data: parms,
					header: {
						"usertoken": token
					},
					method: "POST",
					success(res) {
						console.log(res.data)
						if (res.data.status == 200) {
							uni.showToast({
								duration: 800,
								title: "数据已上传"
							})
						}
					},
					fail: () => {
						uni.showToast({
							duration: 800,
							title: "提交数据失败"
						})
					}
				})
			}
		}
	}
</script>